$(function() {
	var operation = {// 操作按钮  调取url
			delFun: rootPath + '/user/deleteEntity.shtml',
			editFun: rootPath + '/user/editUI.shtml?id=',
//			permissions : rootPath + '/user/permissions.shtml?id=',
			addFun : rootPath + '/user/addUI.shtml',
			leaveFun: rootPath + '/user/leave.shtml?id=',
			unfreezeFun: rootPath + '/user/unfreeze.shtml?id='
		}
	$.ajax({
		url:rootPath + '/user/getButton.shtml',//请求获取按钮
		success:function(data){
			var button = data;
			TableData({
				gaine : 'paging',//id名
				table:'user',
				column : [ {
					colkey : "userName",
					name : "用户名"
				}, {
					colkey : "accountName",
					name : "账号"
				},{
					colkey : "roleName",
					name : "职位"
				}, {
					colkey : "locked",
					name : "账号状态",
					render:function(data,type,row,meta){
						switch (data){
						case '0':
							return '冻结';
							break;
						case '1':
							return '正常';
							break;
					}
					}
				}, {
					colkey : "addName",
					name : "创建人"
				},{
					colkey : "description",
					name : "描述"
				},  {
					colkey : "parentName",
					name : "上级"
				},{
					colkey : "createTime",
					name : "创建时间"
				}, {
					colkey : "updateTime",
					name : "修改时间"
				}, {
					colkey : "operation",
					name : "操作",
					"orderable": false,
					render:function(data,type,row,meta){
					if(button !== ''){
							  button = button.replace("\"","");
							  button = button.replace("\"","");
					        }
						return button;
					}
				} ],
				url : rootPath + '/user/findByPage.shtml',//表格数据请求地址
				success:function(){ //将事件绑定在body上
					user = function(e){
					    var e = e||window.event;
					    var target = $(e.target || e.srcElement);
					    //新增
					    if(target.hasClass('addFun')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.addFun,'addFun',id)
					    }
					    // 编辑
					    if(target.hasClass('editFun')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.editFun,'editFun',id)
					    }
					   //  删除
					    if(target.hasClass('delFun')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.delFun,'delFun',id)
					    }
					    // 下拉选择
					    if(target.hasClass('permissions')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.permissions,'permissions',id)
					    }
					    if(target.hasClass('leaveFun')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.leaveFun,'leaveFun',id)
					    }
					    if(target.hasClass('unfreezeFun')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.unfreezeFun,'unfreezeFun',id)
					    }
					    
					    /*
					    if(target.hasClass('unfreezeFun')){
					    	cover._Body();//防止多次点击
					    	var id = target.parent().parent().attr('dataid');
					    	_click(operation.leaveFun,'unfreezeFun',id)
					    	target.addClass('leaveFun').removeClass('unfreezeFun');
					    	target.attr('title','设置为离职')
					    }*/
				   }
				   $("#user_wrapper").off("click", user);
				   $("#user_wrapper").on('click', user);
				}
			 });	
		}
	})
	
	
});


